﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Frame.Lib.Common
{
    /// <summary>
    /// 全局变量类
    /// </summary>
    public sealed class GlobalVar
    {
        private static string webAppPath;

        #region 获得应用程序系统虚拟路径
        /// <summary>
        /// 获得应用程序系统虚拟路径
        /// </summary>
        /// <returns></returns>
        public static string WebAppPath
        {
            get
            {
                if (webAppPath == null)
                {
                    if (string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["WebAppPath"]))
                    {
                        webAppPath = System.Web.HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + "/";
                    }
                    else
                    {
                        webAppPath = System.Configuration.ConfigurationManager.AppSettings["WebAppPath"].TrimEnd('/') + "/";
                    }
                }
                return webAppPath;
            }
        }
        #endregion

        public static string WebAppUrl
        {
            get
            {
                return System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + WebAppPath;
            }
        }

        #region 获得执行页面的当前路径
        /// <summary>
        /// 获得执行页面的当前路径
        /// </summary>
        /// <returns></returns>
        public static string WebCurrPath
        {
            get
            {
                string strPath = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath;
                int last = strPath.LastIndexOf("/");
                strPath = strPath.Substring(0, last + 1);
                return strPath;
            }
        }
        #endregion

    }
}
